<template>
  <el-container>
    <el-header>
      <span>后台管理系统</span>
      <!--<el-link href="login">退出登入</el-link>-->
      <router-link to="login">退出登入</router-link>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-container>
          <el-menu
              active-text-color="#409EFF"
              style="height: 400px!important;">
            <el-menu-item
                v-for="item in list" :index=item.id :key="item.id" @click="add(item.id)">
              <i class="el-icon-menu"></i>
              <span slot="title">{{ item.title }}</span>
            </el-menu-item>
          </el-menu>
        </el-container>
      </el-aside>
      <el-main>
        <!--使用路由实现页面切换-->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import {nanoid} from 'nanoid'

export default {
  name: "Home",
  data() {
    return {
      list: [
        {id: nanoid(), path: 'user1', title: '用户管理'},
        {id: nanoid(), path: 'jur2', title: '权限管理'},
        {id: nanoid(), path: 'mer3', title: '商品管理'},
        {id: nanoid(), path: 'indent4', title: '订单管理'},
        {id: nanoid(), path: 'sys5', title: '系统管理'}
      ]
    }
  },
  methods: {
    add(id) {
      console.log('ok')
      this.list.forEach((item, index) => {
        if (id === item.id) {
          this.$router.push(`/home/${this.list[index].path}`)
        }
      })
    }
  }
}
</script>

<style scoped>
#app {
  height: 356px;
}

.el-header, .el-footer {
  background-color: #B3C0D1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-header span {
  float: left;
  font-size: 20px;
}

.el-header a {
  float: right;
}

.el-menu {
  width: 100%;
}
</style>